package com.qiaofang.housewarehouse.facade.impl;

import com.qiaofang.housewarehouse.service.HouseCollectionCharacterService;
import com.qiaofang.housewarehouse.stub.constants.ResponseCode;
import com.qiaofang.housewarehouse.stub.facade.HouseCollectionCharacterFacade;
import com.qiaofang.housewarehouse.stub.request.CityDistricRequest;
import com.qiaofang.housewarehouse.stub.request.HouseCollectionCharacterRequest;
import com.qiaofang.housewarehouse.stub.response.HouseCollectionCharacterResponse;
import com.qiaofang.housewarehouse.stub.response.SaleAndRentalByCityResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 根据城市区域查询质量服务接口实现
 */
@RestController
public class HouseCollectionCharacterFacadeImpl implements HouseCollectionCharacterFacade {

    private static final Logger logger = LoggerFactory.getLogger(HouseCollectionCharacterFacadeImpl.class);

    @Autowired
    HouseCollectionCharacterService houseCollectionCharacterService;
    /**
     * 查询城市下的出租和出售情况
     * @param cityDistricRequest
     * @return
     */
    @Override
    public SaleAndRentalByCityResponse querySaleAndRentalByCity(@RequestBody @Valid CityDistricRequest cityDistricRequest) {
        SaleAndRentalByCityResponse response = new SaleAndRentalByCityResponse();
        try {
            response.setData(houseCollectionCharacterService.querySaleAndRentalByCity(cityDistricRequest.getCityName()));
            response.setResponseCode(ResponseCode.RC_SUCCESS.getResponseCode());
            response.setResponseMessage(ResponseCode.RC_SUCCESS.getResponseMessage());
        }catch (Exception e){
            response.setResponseCode(ResponseCode.RC_EXCEPTION_ERROR.getResponseCode());
            response.setResponseMessage(ResponseCode.RC_EXCEPTION_ERROR.getResponseMessage());
            logger.error("[查询城市下出租出售情况] CityQueryFacadeImpl querySaleAndRentalByCity error！", e);
        }
        return response;
    }


}
